<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico">
  <link rel="mask-icon" href="/images/favicon.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"always","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="平常写代码的时候很多细节没有注意，就是凭感觉和习惯，理论很少去记，因此记录下来作为复习和回顾">
<meta property="og:type" content="article">
<meta property="og:title" content="java基础笔记（占坑）">
<meta property="og:url" content="http://yoursite.com/2018/12/21/java-2018-12-21-JavaBasic/index.html">
<meta property="og:site_name" content="Akiyama&#39;s Blog">
<meta property="og:description" content="平常写代码的时候很多细节没有注意，就是凭感觉和习惯，理论很少去记，因此记录下来作为复习和回顾">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2018-12-20T16:00:00.000Z">
<meta property="article:modified_time" content="2021-05-16T10:05:30.260Z">
<meta property="article:author" content="丘山月夜">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2018/12/21/java-2018-12-21-JavaBasic/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>java基础笔记（占坑） | Akiyama's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Akiyama's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">丘山月夜的博客</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="home fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="user fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="tags fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="th fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="archive fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/12/21/java-2018-12-21-JavaBasic/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="丘山月夜">
      <meta itemprop="description" content="君は空を見てるか,<br>風の音を聞いてるか">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Akiyama's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          java基础笔记（占坑）
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-12-21 00:00:00" itemprop="dateCreated datePublished" datetime="2018-12-21T00:00:00+08:00">2018-12-21</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-05-16 18:05:30" itemprop="dateModified" datetime="2021-05-16T18:05:30+08:00">2021-05-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/" itemprop="url" rel="index"><span itemprop="name"></span></a>
                </span>
            </span>

          
            <div class="post-description">平常写代码的时候很多细节没有注意，就是凭感觉和习惯，理论很少去记，因此记录下来作为复习和回顾</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="1-知识点"><a href="#1-知识点" class="headerlink" title="1. 知识点"></a>1. 知识点</h1><h2 id="1-1-重写和重载"><a href="#1-1-重写和重载" class="headerlink" title="1.1. 重写和重载"></a>1.1. 重写和重载</h2><ul>
<li>重写：子类对父类方法重新定义，具有相同的方法名，参数，返回类型，若是重写了方法，则要使用父类方法需要使用super，子类访问权限不能比父类严格，子类抛出异常范围不能比父类大（RuntimeException除外）</li>
<li>重载：参数个数、类型不同，返回值可以不同</li>
</ul>
<h2 id="1-2-数组定义"><a href="#1-2-数组定义" class="headerlink" title="1.2. 数组定义"></a>1.2. 数组定义</h2><ul>
<li>定义一维数组时，必须显式指明数组的长度； </li>
<li>定义多维数组时，其一维数组的长度必须首先指明，其他维数组长度可以稍后指定； </li>
<li>采用给定值初始化数组时，不必指明长度； <code>int[] a = &#123;1, 2, 3&#125;</code></li>
<li>“[]” 是数组运算符的意思，在声明一个数组时，数组运算符可以放在数据类型与变量之间，也可以放在变量之后。</li>
</ul>
<p>二维数组声明可以如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> a[][] = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">10</span>][<span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> []b[] = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">10</span>][<span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> [][]c = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">10</span>][<span class="number">10</span>];</span><br><span class="line"><span class="comment">//多维数组可以先声明第一维长度，后面的长度可以稍后声明</span></span><br><span class="line"><span class="keyword">int</span> d[][] = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">10</span>]【】;</span><br></pre></td></tr></table></figure>

<h2 id="1-3-四种引用"><a href="#1-3-四种引用" class="headerlink" title="1.3. 四种引用"></a>1.3. 四种引用</h2><ul>
<li>强引用：普通的引用</li>
<li>软引用：内存不足时被回收</li>
<li>弱引用：除了弱引用外没有其他的引用则会被回收</li>
<li>虚引用：相当于没有引用，要与引用队列配合使用<ul>
<li>可以进行重要对象回收监听，进行日志统计</li>
<li>系统gc监听：因为虚引用每次GC都会被回收，那么我们就可以通过虚引用来判断gc的频率，如果频率过大，内存使用可能存在问题，才导致了系统gc频繁调用</li>
</ul>
</li>
</ul>
<p>引用队列：引用的对象将要被JVM回收时，会将其加入到引用队列中。通过引用队列可以了解JVM垃圾回收情况。</p>
<h1 id="2-细节"><a href="#2-细节" class="headerlink" title="2. 细节"></a>2. 细节</h1><h2 id="2-1-amp-amp-和-amp-的区别"><a href="#2-1-amp-amp-和-amp-的区别" class="headerlink" title="2.1. &amp;&amp;和&amp;的区别"></a>2.1. &amp;&amp;和&amp;的区别</h2><ul>
<li>&amp;&amp;：短路与，即前面的表达式能确定结果就不执行后面的表达式，可以用来代替简单的if语句</li>
<li>&amp;：不短路与，前后表达式都需要执行</li>
</ul>
<h2 id="2-2-接口可以继承多个接口"><a href="#2-2-接口可以继承多个接口" class="headerlink" title="2.2. 接口可以继承多个接口"></a>2.2. 接口可以继承多个接口</h2><ul>
<li>类只能继承一个类，但可以实现多个接口</li>
<li>接口不可以实现接口，但可以继承多个接口（不用实现） A extends B,C</li>
</ul>
<h2 id="2-3-equals和"><a href="#2-3-equals和" class="headerlink" title="2.3. equals和=="></a>2.3. equals和==</h2><p>==判断是否是同一个对象（对于非基本类型）</p>
<p>equals判断的是内容是否相同，可以通过重写对象的equals方法来自定义比较规则</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//例</span></span><br><span class="line">String a = <span class="keyword">new</span> String(<span class="string">&quot;123&quot;</span>);</span><br><span class="line">String b = <span class="keyword">new</span> String(<span class="string">&quot;123&quot;</span>);</span><br><span class="line">System.out.println(a==b);<span class="comment">//false</span></span><br><span class="line">System.out.println(a.equals(b));<span class="comment">//true</span></span><br></pre></td></tr></table></figure>

<h2 id="2-3-String常量池"><a href="#2-3-String常量池" class="headerlink" title="2.3. String常量池"></a>2.3. String常量池</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">String a = <span class="string">&quot;123&quot;</span>;</span><br><span class="line">String b = <span class="string">&quot;123&quot;</span>;</span><br><span class="line">System.out.println(a==b);<span class="comment">//true：同一个对象。</span></span><br><span class="line"><span class="comment">//使用双引号创建的是字符串常量，存储在常量池中</span></span><br><span class="line"><span class="comment">//创建常量对象的时候会先判断常量池中是否已经存在，如果存在则直接引用</span></span><br><span class="line"></span><br><span class="line">String a = <span class="string">&quot;123&quot;</span>;</span><br><span class="line">String b = <span class="keyword">new</span> String(<span class="string">&quot;123&quot;</span>);</span><br><span class="line">System.out.println(a==b);<span class="comment">//false</span></span><br><span class="line"><span class="comment">//使用new String创建对象，存放在堆中，两个引用不相等</span></span><br><span class="line"><span class="comment">//实际上是将常量池中的123复制到了堆中，如果常量池没有，会先再常量池中创建，如下</span></span><br><span class="line"></span><br><span class="line">String a = <span class="keyword">new</span> String(<span class="string">&quot;123&quot;</span>);</span><br><span class="line"><span class="comment">//实际上创建了两个对象，一个在常量池，一个在堆中</span></span><br><span class="line"><span class="comment">//如果前面常量池已经有该字符串，则只创建一个对象。</span></span><br></pre></td></tr></table></figure>

<h2 id="2-4-继承时构造方法"><a href="#2-4-继承时构造方法" class="headerlink" title="2.4. 继承时构造方法"></a>2.4. 继承时构造方法</h2><ul>
<li>子类构造方法总是先调用父类的构造方法，如果没有显式指明调用父类哪个构造方法，则默认调用无参构造方法</li>
<li>若父类没有无参构造方法，子类需要在自己的构造函数中显式调用父类的构造函数<code>super(arg);</code>，并且一定要在第一行调用。若不调用，编译器会报错</li>
</ul>
<h2 id="2-5-继承时初始化顺序"><a href="#2-5-继承时初始化顺序" class="headerlink" title="2.5. 继承时初始化顺序"></a>2.5. 继承时初始化顺序</h2><ul>
<li>父类的静态变量</li>
<li>父类静态代码块</li>
<li>子类的静态变量</li>
<li>子类的静态代码块</li>
<li>父类的普通变量</li>
<li>父类普通代码块</li>
<li>父类无参构造函数</li>
<li>子类的普通变量</li>
<li>子类普通代码块</li>
<li>子类无参构造函数</li>
</ul>
<h2 id="2-6-自动装箱-拆箱"><a href="#2-6-自动装箱-拆箱" class="headerlink" title="2.6. 自动装箱/拆箱"></a>2.6. 自动装箱/拆箱</h2><p>装箱：将8个基本类型转换成对应的包装类型。拆箱则反过来</p>
<h3 id="2-6-1-基本数据类型和包装类"><a href="#2-6-1-基本数据类型和包装类" class="headerlink" title="2.6.1. 基本数据类型和包装类"></a>2.6.1. 基本数据类型和包装类</h3><p>在Java语言中，<code>new</code>一个对象是存储在堆里的，我们通过栈中的引用来使用这些对象；所以，对象本身来说是比较消耗资源的。对于经常用到的类型，如int等，如果我们每次使用这种变量的时候都需要new一个Java对象的话，就会比较笨重。</p>
<p>Java是一种面向对象语言，很多地方都需要使用对象而不是基本数据类型。比如，在集合类中，我们是无法将int 、double等类型放进去的。因为集合的容器要求元素是Object类型。为了让基本类型也具有对象的特征，就出现了包装类型，它相当于将基本类型“包装起来”，使得它具有了对象的性质，并且为其添加了属性和方法，丰富了基本类型的操作。</p>
<table>
<thead>
<tr>
<th>基本数据类型（内置类型）</th>
<th>对应的包装类型</th>
<th>大小</th>
</tr>
</thead>
<tbody><tr>
<td>byte</td>
<td>Byte</td>
<td>1个字节</td>
</tr>
<tr>
<td>boolean</td>
<td>Boolean</td>
<td>1个字节或4个字节</td>
</tr>
<tr>
<td>char</td>
<td>Character</td>
<td>4字节</td>
</tr>
<tr>
<td>short</td>
<td>Short</td>
<td>2个字节</td>
</tr>
<tr>
<td>int</td>
<td>Integer</td>
<td>4个字节</td>
</tr>
<tr>
<td>long</td>
<td>Long</td>
<td>8个字节</td>
</tr>
<tr>
<td>float</td>
<td>Float</td>
<td>4字节</td>
</tr>
<tr>
<td>double</td>
<td>Double</td>
<td>8字节</td>
</tr>
</tbody></table>
<p>实际上，Java中还存在另外一种基本类型<code>void</code>，它也有对应的包装类<code>java.lang.Void</code>，不过我们无法直接对它们进行操作。</p>
<p><strong>补充：数据超出范围，溢出不会抛异常，也没有任何提示。</strong></p>
<p>boolean类型占1或4个字节：理论上只需要1bit空间，但是计算机处理数据的最小单位是1个字节，实际存储的空间是：用1个字节的最低位存储，其他7位用0填补</p>
<p>位（bit）是计算机存储的最小单位，字节是计算机处理数据的最小单位，1字节=8位</p>
<blockquote>
<p>《Java虚拟机规范》一书中的描述：“虽然定义了boolean这种数据类型，但是只对它提供了非常有限的支持。在Java虚拟机中没有任何供boolean值专用的字节码指令，Java语言表达式所操作的boolean值，在编译之后都使用Java虚拟机中的int数据类型来代替，而boolean数组将会被编码成Java虚拟机的byte数组，每个元素boolean元素占8位”。这样我们可以得出boolean类型占了单独使用是4个字节，在数组中又是1个字节。</p>
<p>使用int的原因是，对于当下32位的处理器（CPU）来说，一次处理数据是32位（这里不是指的是32/64位系统，而是指CPU硬件层面），具有高效存取的特点。</p>
</blockquote>
<h3 id="2-6-2-自动装箱、拆箱"><a href="#2-6-2-自动装箱、拆箱" class="headerlink" title="2.6.2. 自动装箱、拆箱"></a>2.6.2. 自动装箱、拆箱</h3><ul>
<li>在Java SE5之前，装箱：<code>Integer i = new Integer(10);</code></li>
<li>在Java SE5中，提供了自动装箱、拆箱功能</li>
</ul>
<p>自动装箱、拆箱原理：通过包装类的valueOf()和xxxValue();方法实现</p>
<p>举例：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Integer i =<span class="number">10</span>;  <span class="comment">//自动装箱</span></span><br><span class="line"><span class="keyword">int</span> b= i;     <span class="comment">//自动拆箱</span></span><br></pre></td></tr></table></figure>

<p>将上述代码反编译后得到</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span>  <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[]args)</span></span>&#123;</span><br><span class="line">    Integer integer=Integer.valueOf(<span class="number">1</span>); <span class="comment">//装箱</span></span><br><span class="line">    <span class="keyword">int</span> i=integer.intValue(); <span class="comment">//拆箱</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="2-6-3-常见场景"><a href="#2-6-3-常见场景" class="headerlink" title="2.6.3 常见场景"></a>2.6.3 常见场景</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//基本数据类型放入集合类</span></span><br><span class="line">List&lt;Integer&gt; li = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; <span class="number">50</span>; i ++)&#123;</span><br><span class="line">    li.add(i);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//包装类型与基本数据类型比较</span></span><br><span class="line"><span class="comment">//理论上==是比较对象地址，这里实现了拆箱</span></span><br><span class="line">Integer a=<span class="number">1</span>;</span><br><span class="line">System.out.println(a==<span class="number">1</span>?<span class="string">&quot;等于&quot;</span>:<span class="string">&quot;不等于&quot;</span>);<span class="comment">//等于</span></span><br><span class="line">Boolean bool=<span class="keyword">false</span>;</span><br><span class="line">System.out.println(bool?<span class="string">&quot;真&quot;</span>:<span class="string">&quot;假&quot;</span>);<span class="comment">//真</span></span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//包装类型的运算</span></span><br><span class="line">Integer i = <span class="number">10</span>;</span><br><span class="line">Integer j = <span class="number">20</span>;</span><br><span class="line">System.out.println(i+j);</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//三目运算符使用，当第二，第三位操作数分别为基本类型和对象时，其中的对象就会拆箱为基本类型进行操作。</span></span><br><span class="line"><span class="keyword">boolean</span> flag = <span class="keyword">true</span>;</span><br><span class="line">Integer i = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> j = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">int</span> k = flag ? i : j;<span class="comment">//这里对i进行拆箱，如果是null，会发生NPE，拆箱：i.intValue();</span></span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//函数参数和返回值</span></span><br><span class="line"><span class="comment">//自动拆箱</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getNum1</span><span class="params">(Integer num)</span> </span>&#123;</span><br><span class="line"> <span class="keyword">return</span> num;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//自动装箱</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> Integer <span class="title">getNum2</span><span class="params">(<span class="keyword">int</span> num)</span> </span>&#123;</span><br><span class="line"> <span class="keyword">return</span> num;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h1 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a>参考文章</h1><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/wufaliang003/article/details/82347077">什么是Java中的自动拆装箱</a></p>
<p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/2f663dc820d0">你真的知道Java中boolean类型占用多少个字节吗？</a></p>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/images/wechat_channel.jpg">
            <span class="icon">
              <i class="fab fa-weixin"></i>
            </span>

            <span class="label">WeChat</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/" rel="tag"><i class="fa fa-tag"></i> </a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2018/12/14/tool-2018-12-14-Cmder/" rel="prev" title="Cmder——Windows下好用的命令行工具">
      <i class="fa fa-chevron-left"></i> Cmder——Windows下好用的命令行工具
    </a></div>
      <div class="post-nav-item">
    <a href="/2018/12/28/basic-2018-12-28-Network/" rel="next" title="网络相关">
      网络相关 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="header-overlay"></div>
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-%E7%9F%A5%E8%AF%86%E7%82%B9"><span class="nav-number">1.</span> <span class="nav-text">1. 知识点</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-1-%E9%87%8D%E5%86%99%E5%92%8C%E9%87%8D%E8%BD%BD"><span class="nav-number">1.1.</span> <span class="nav-text">1.1. 重写和重载</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-%E6%95%B0%E7%BB%84%E5%AE%9A%E4%B9%89"><span class="nav-number">1.2.</span> <span class="nav-text">1.2. 数组定义</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-3-%E5%9B%9B%E7%A7%8D%E5%BC%95%E7%94%A8"><span class="nav-number">1.3.</span> <span class="nav-text">1.3. 四种引用</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-%E7%BB%86%E8%8A%82"><span class="nav-number">2.</span> <span class="nav-text">2. 细节</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#2-1-amp-amp-%E5%92%8C-amp-%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="nav-number">2.1.</span> <span class="nav-text">2.1. &amp;&amp;和&amp;的区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-2-%E6%8E%A5%E5%8F%A3%E5%8F%AF%E4%BB%A5%E7%BB%A7%E6%89%BF%E5%A4%9A%E4%B8%AA%E6%8E%A5%E5%8F%A3"><span class="nav-number">2.2.</span> <span class="nav-text">2.2. 接口可以继承多个接口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-3-equals%E5%92%8C"><span class="nav-number">2.3.</span> <span class="nav-text">2.3. equals和&#x3D;&#x3D;</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-3-String%E5%B8%B8%E9%87%8F%E6%B1%A0"><span class="nav-number">2.4.</span> <span class="nav-text">2.3. String常量池</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-4-%E7%BB%A7%E6%89%BF%E6%97%B6%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95"><span class="nav-number">2.5.</span> <span class="nav-text">2.4. 继承时构造方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-5-%E7%BB%A7%E6%89%BF%E6%97%B6%E5%88%9D%E5%A7%8B%E5%8C%96%E9%A1%BA%E5%BA%8F"><span class="nav-number">2.6.</span> <span class="nav-text">2.5. 继承时初始化顺序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-6-%E8%87%AA%E5%8A%A8%E8%A3%85%E7%AE%B1-%E6%8B%86%E7%AE%B1"><span class="nav-number">2.7.</span> <span class="nav-text">2.6. 自动装箱&#x2F;拆箱</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6-1-%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%8C%85%E8%A3%85%E7%B1%BB"><span class="nav-number">2.7.1.</span> <span class="nav-text">2.6.1. 基本数据类型和包装类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6-2-%E8%87%AA%E5%8A%A8%E8%A3%85%E7%AE%B1%E3%80%81%E6%8B%86%E7%AE%B1"><span class="nav-number">2.7.2.</span> <span class="nav-text">2.6.2. 自动装箱、拆箱</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-6-3-%E5%B8%B8%E8%A7%81%E5%9C%BA%E6%99%AF"><span class="nav-number">2.8.</span> <span class="nav-text">2.6.3 常见场景</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%AB%A0"><span class="nav-number">3.</span> <span class="nav-text">参考文章</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="丘山月夜"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">丘山月夜</p>
  <div class="site-description" itemprop="description">君は空を見てるか,<br>風の音を聞いてるか</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">60</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">21</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">丘山月夜</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
